package com.knight.concurrent.chapter9;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Description:
 * @author: knight
 * @Date: 2019-03-09 10:34
 */
public class Test2 {

    public void test() {
       /* Arrays.asList(Thread.currentThread().getStackTrace()).stream().filter(stackTraceElement ->
                !stackTraceElement.isNativeMethod()
        ).forEach(e -> Optional.of(e.getClassName() + ":" + e.getMethodName() + ":" + e.getLineNumber()).ifPresent(System.out::println));*/

        // 代码是相同的
        StackTraceElement[] stackTraces = Thread.currentThread().getStackTrace();
        if (stackTraces != null && stackTraces.length > 0) {
            for (StackTraceElement stackTrace : stackTraces) {
                if (!stackTrace.isNativeMethod()) {
                    System.out.println(stackTrace.getClassName() + ":" + stackTrace.getMethodName() + ":" + stackTrace.getLineNumber());
                }
            }
        }
    }
}
